package com.jarpackage.config;

import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class AppConfig {
    private List<RepositoryConfig> repositories;
    private String defaultDownloadPath;
    private Settings settings;

    public AppConfig() {
        repositories = new ArrayList<>();
        settings = new Settings();
    }

    public static AppConfig load(String configPath) throws IOException {
        ObjectMapper mapper = new ObjectMapper();
        return mapper.readValue(new File(configPath), AppConfig.class);
    }

    public void save(String configPath) throws IOException {
        ObjectMapper mapper = new ObjectMapper();
        mapper.writeValue(new File(configPath), this);
    }

    public List<RepositoryConfig> getRepositories() {
        return repositories;
    }

    public void setRepositories(List<RepositoryConfig> repositories) {
        this.repositories = repositories;
    }

    public String getDefaultDownloadPath() {
        return defaultDownloadPath;
    }

    public void setDefaultDownloadPath(String defaultDownloadPath) {
        this.defaultDownloadPath = defaultDownloadPath;
    }

    public Settings getSettings() {
        return settings;
    }

    public void setSettings(Settings settings) {
        this.settings = settings;
    }

    public static class Settings {
        private boolean downloadDependencies;
        private boolean validateChecksum;

        public boolean isDownloadDependencies() {
            return downloadDependencies;
        }

        public void setDownloadDependencies(boolean downloadDependencies) {
            this.downloadDependencies = downloadDependencies;
        }

        public boolean isValidateChecksum() {
            return validateChecksum;
        }

        public void setValidateChecksum(boolean validateChecksum) {
            this.validateChecksum = validateChecksum;
        }
    }
}